<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
/* @var $this \Magento\Reports\Block\Product\Widget\Viewed\Item */
?>

<?php
$type = $this->getType() . '-' . $this->getViewMode();

$item = $this->getProduct();

$imageBlock =  $this->getLayout()->createBlock('Magento\Catalog\Block\Product\Image');
$image = $this->getImageType();
$rating = 'short';
?>
<div class="block" id="widget_viewed_item" data-sku="<?php echo $item->getSku(); ?>" style="display: none;">
    <li class="item product">
        <div class="product">
            <?php echo '<!-- ' . $image . '-->' ?>
            <a href="<?php echo $this->getProductUrl($item) ?>" class="product photo">
                <?php echo $imageBlock->init($item, $image)->toHtml() ?>
            </a>
            <div class="product details">
                <strong class="product name"><a title="<?php echo $this->escapeHtml($item->getName()) ?>" href="<?php echo $this->getProductUrl($item) ?>">
                    <?php echo $this->escapeHtml($item->getName()) ?></a>
                </strong>

                <?php echo $this->getProductPriceHtml(
                    $item,
                    \Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
                    \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
                    [
                        'price_id_suffix' => '-' . $type
                    ]
                ) ?>

                <?php if ($rating): ?>
                    <?php echo $this->getReviewsSummaryHtml($item, $rating) ?>
                <?php endif; ?>

                <div class="product actions">
                    <div class="primary">
                        <?php if($item->isSaleable()): ?>
                            <?php if ($item->getTypeInstance()->hasRequiredOptions($item)): ?>
                                <button class="action tocart" data-mage-init='{"redirectUrl": {"url": "<?php echo $this->getAddToCartUrl($item) ?>"}}' type="button" title="<?php echo __('Add to Cart') ?>">
                                    <span><?php echo __('Add to Cart') ?></span>
                                </button>
                            <?php else: ?>
                                <?php $postDataHelper = $this->helper('Magento\Core\Helper\PostData');
                                $postData = $postDataHelper->getPostData($this->getAddToCartUrl($item), ['product' => $item->getEntityId()])
                                ?>
                                <button class="action tocart"
                                        data-post='<?php echo $postData; ?>'
                                        type="button" title="<?php echo __('Add to Cart') ?>">
                                    <span><?php echo __('Add to Cart') ?></span>
                                </button>
                            <?php endif; ?>
                        <?php else: ?>
                            <?php if ($item->getIsSalable()): ?>
                                <p class="stock available"><span><?php echo __('In stock') ?></span></p>
                            <?php else: ?>
                                <p class="stock unavailable"><span><?php echo __('Out of stock') ?></span></p>
                            <?php endif; ?>
                        <?php endif; ?>
                    </div>

                    <div class="secondary-addto-links" data-role="add-to-links">
                        <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
                            <a href="#" data-post='<?php echo $this->getAddToWishlistParams($item); ?>'  class="action towishlist" data-action="add-to-wishlist" title="<?php echo __('Add to Wishlist') ?>">
                                <span><?php echo __('Add to Wishlist') ?></span>
                            </a>
                        <?php endif; ?>
                        <?php if($this->getAddToCompareUrl()): ?>
                            <?php
                            $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
                            ?>
                            <a href="#" class="action tocompare"
                               data-post='<?php echo $compareHelper->getPostDataParams($item);?>'
                               data-role="add-to-links"
                               title="<?php echo __('Add to Compare'); ?>">
                                <span><?php echo __('Add to Compare') ?></span>
                            </a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </li>
</div>
